﻿using Grpc.Net.Client;
using GrpcService1;
using Microsoft.Extensions.DependencyInjection;

namespace ClientGRPC2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection services = new ServiceCollection();
            services.AddTransient<GrpcTest>();
            #region gRPC Client注册
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);  
            services.AddGrpcClient<Greeter.GreeterClient>(options => //这里要引用Grpc.AspNetCore
            {
                options.Address = new Uri("https://localhost:5001");
            }).ConfigureChannel(grpcOptions =>
            {
                //可以完成各种配置，比如token
            });
            #endregion

            //构建容器
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            //解析grpc请求测试
            var grpcRequestTest = serviceProvider.GetService<GrpcTest>();
            //执行
            grpcRequestTest.CreateHello();
        }
    }
}